/*
 * RegistrationDate.cpp
 *
 *  Created on: 3 May 2010
 *      Author: Savramis Sartios
 */

#include "RegistrationDate.h"

RegistrationDate::RegistrationDate(ICourseRegistration *registration,const string *day,const string *month,const string *year) : IDate(registration) {
	setDate(day,month,year);
}

RegistrationDate::~RegistrationDate() {
	delete day_;
	delete month_;
	delete year_;
}

/**
 *	Set's the date of registration
 *
 *	This version doesn't test if the month has 30 or 31 days.
 *	For each month except Febr, standar 30 days. For Febr 28.
 *	If the values are not correct, pointers to null
 */
void	RegistrationDate::setDate(const string *day,const string *month,const string *year){

	if((0!=day)&&(0!=month)&&(0!=year)){
/*		year_ = (1900<atoi(year->c_str()))?year:0;*/
/*		month_ = ((0<atoi(month->c_str()))&&(13>atoi(month->c_str())))?month:0;*/
		/*if((2==atoi(month->c_str()))){
			day_ = ((0<atoi(day->c_str()))&&(29>atoi(day->c_str())))?day:0;
		}
		day_ = ((0<atoi(day->c_str()))&&(31>atoi(day->c_str())))?day:0;*/

		this->setYear(year);
		this->setMonth(month);
		this->setDay(day);
	}
}

/**
 * Returns a string which contains the date like dd/mm/yyyy
 */
string * RegistrationDate::getDate()const{
	return new string(*(this->getDay())+"/"+*(this->getMonth())+"/"+*(this->getYear()));
}

/**
 * Sets the day by checking the month
 * \throw InvalidDay
 */

void	RegistrationDate::setDay(const string *day){

	if((0!=this->getMonth())&&(2==atoi(this->getMonth()->c_str()))){
		day_ = (((0<atoi(day->c_str()))&&(29>atoi(day->c_str()))))?new string(*day):0/*throw InvalidDay*/;
	}
	else{
	day_ = ((0<atoi(day->c_str()))&&(31>atoi(day->c_str())))?new string(*day):0/*throw InvalidDay*/;
	}
}

/**
 *	Sets month
 *	\throw InvalidMonth
 */
void RegistrationDate::setMonth(const string *month){

	if(0!=month){
		month_ = ((0<atoi(month->c_str()))&&(13>atoi(month->c_str())))?new string(*month):0/*throw NullMonth*/;
	}

}

/**
 *	Sets year
 *	\throw InvalidYear
 */
void RegistrationDate::setYear(const string *year){
	if(0!=year){
		year_ = (1900<atoi(year->c_str()))?new string(*year):0/*throw InvalidYear*/;
	}
}

string * RegistrationDate::getYear()const{
	return year_;
}

string * RegistrationDate::getMonth()const{
	return month_;
}

string * RegistrationDate::getDay()const{
	return day_;
}

void RegistrationDate::setOwner(const string * aem){
	ACourseRegistrationDecorator::registration_->setOwner(aem);
}

string * RegistrationDate::getOwner()const{
	return ACourseRegistrationDecorator::registration_->getOwner();
}
